<template>
  <view>
    <learn-base ref="learnBaseDom" :courseId="courseId" :learnChapterId="chapterId" @handleBackPress="handleBackPress"></learn-base>
  </view>
</template>

<script setup>
import { ref, getCurrentInstance, onMounted } from 'vue';
import {onLoad, onHide, onBackPress} from '@dcloudio/uni-app'
import learnBase from '@/view/course/Learn';
const {$api, $toast, $uniPush, $uniRedirectTo, $dialog} = getCurrentInstance()?.proxy
// 定义响应式数据
const chapterId = ref('');
const courseId = ref('');
const backPress = ref(false);
const learnBaseDom = ref(null);

// 生命周期函数
onLoad((query) => {
  chapterId.value = query.chapter || "";
  courseId.value = query.id || '';
});
onMounted(()=>{
  // console.log(`=>(chapter.vue:26) learnBaseDom`, learnBaseDom.value);
})
onHide(() => {
  // console.log(`=>(chapter.vue:26) learnBaseDom`, learnBaseDom.value);
  if (learnBaseDom.value && learnBaseDom.value.handleHide) {
    learnBaseDom.value.handleHide();
  }
});

onBackPress((options) => {
  if (backPress.value) {
    if (learnBaseDom.value && learnBaseDom.value.saveCourseRecords) {
      learnBaseDom.value.saveCourseRecords();
    }
    $dialog.alert({
      message: '是否退出课程学习',
      showConfirmButton: true
    }).then(() => {
      backPress.value = false
      uni.navigateBack({ delta: 1 })
    })
    return true
  }
  return false;
});

// 方法
const handleBackPress = () => {
  backPress.value = true;
};
</script>

<style scoped>
/* 你的样式 */
</style>